/**
 * 
 */
package garin.parse;

public final class TagString extends StringToken {
	private final char tag2;
	private boolean exit;
	private int ignore = 1;
	private boolean seekTag = true;
	private boolean init = true;
	
	public TagString(final Token parent, final char tag1, final char tag2) {
		super(parent, "" + tag1);
		this.tag2 = tag2;
	}
	
	@Override
	public Token on() throws Exception {
		if (init) {
			init = false;
			start = at();
		}
		if (ignore > 0) {
			ignore--;
			return self();
		}
		if (exit) return up();
		if (seekTag) {
			if (is(tag2)) {
				seekTag = false;
				close = contents();
			}
		} else
			return super.on();
		return self();
	}
}
